/**显示信息提示模态框*/
yjx.service('modalService', ['$rootScope', '$timeout', function modalService($rootScope, $timeout) {
    var ErrorMsg = '我们的服务器出现异常！'
    var DefaultMsg = '温馨的未知系统提示~'

    function modalExpireFun(timeout, expire) {//延迟消失函数
        if (timeout) {
            if (!expire || !(expire > 0)) {//不存在，或存在且不大于0；
                expire = 2;//默认2秒后自动关闭
            }
            $timeout(function () {
                $rootScope.modalStatus = 'modal-hide';
            }, 1000 * expire)
        }
    }

    return {
        mainMsgOk: function (msg, timeout, expire) {//消息，
            $timeout(function () {
                $rootScope.mainMsg = {};
                $rootScope.mainMsg.template = 'components/common/model/mainMsg.html';

                $rootScope.modalStatus = 'modal-show';
                $rootScope.modalTag = 'modal-msg-min';

                $rootScope.mainMsg.type = 'ok';
                $rootScope.mainMsg.msg = msg ? msg : DefaultMsg;
                timeout = timeout?timeout:true;
                modalExpireFun(timeout, expire);
            })
        },

        mainMsgWarn: function (msg, timeout, expire) {//延迟时间
            $timeout(function () {
                $rootScope.mainMsg = {};
                $rootScope.mainMsg.template = 'components/common/model/mainMsg.html';

                $rootScope.modalStatus = 'modal-show';
                $rootScope.modalTag = 'modal-msg-main';

                $rootScope.mainMsg.type = 'warn';
                $rootScope.mainMsg.msg = msg ? msg : DefaultMsg;
                modalExpireFun(timeout, expire);
            })
        },
        mainMsgError: function (msg, timeout, expire) {
            $timeout(function () {
                $rootScope.mainMsg = {};
                $rootScope.mainMsg.template = 'components/common/model/mainMsgError.html';

                $rootScope.modalStatus = 'modal-show';
                $rootScope.modalTag = 'modal-msg-main';

                $rootScope.mainMsg.type = 'error';
                $rootScope.mainMsg.msg = msg ? msg : ErrorMsg;
            })
        },
        confirm: function (msg, econfirm, ecancel,type) {//消息，确认方法，取消方法
            $timeout(function () {
                $rootScope.mainMsg = {};
                $rootScope.mainMsg.globalTemplate = 'components/common/model/mainConfirm.html';

                $rootScope.modalStatus = 'modal-show';
                $rootScope.modalTag = 'modal-msg-global';

                $rootScope.mainMsg.type = type?type:'info';
                $rootScope.mainMsg.msg = msg;
                $rootScope.mainMsg.sure = {};//确认
                $rootScope.mainMsg.notsure = {};//取消
                $rootScope.mainMsg.sure.click = function () {
                    econfirm();
                }
                $rootScope.mainMsg.notsure.click = function () {
                    if (ecancel) {
                        ecancel();
                    }
                }
            })
        },
        mainMsgInfo: function (msg,btnValue,title,econfirm ,timeout ,expire) {
            $timeout(function () {
                $rootScope.mainMsg = {};
                $rootScope.mainMsg.template = 'components/common/model/mainMsgInfo.html';

                $rootScope.modalStatus = 'modal-show';
                $rootScope.modalTag = 'modal-msg-info';
                $rootScope.mainMsg.sure={};
                $rootScope.mainMsg.sure.click = function () {
                    if(econfirm) {
                        econfirm();
                    }else {
                        return
                    }
                }
                $rootScope.mainMsg.title = title;
                $rootScope.mainMsg.type = 'info';
                $rootScope.mainMsg.msg = msg;
                $rootScope.mainMsg.btnValue = btnValue?btnValue:'确认'
            })
        },
        wxCodeModal:function(){
            $timeout(function () {
                $rootScope.mainMsg = {};
                $rootScope.modalTag = 'wxCodeModal';
                $rootScope.mainMsg.template = 'components/user/withdraw/wxCodeModal.html';
                $rootScope.modalStatus = 'modal-show';

            })
        },
        actsModals:function(){
            $timeout(function(){
                $rootScope.mainMsg = {};
                $rootScope.modalTag = 'actsModals';
                $rootScope.modalStatus='modal-show'
            })
        },
        
        /*点击查看放大图片*/
        openImgLarge:function(urls){
            $timeout(function() {
                //console.log(eval(urls))
                $rootScope.mainMsg = {};
                $rootScope.mainMsg.globalTemplate = 'components/common/model/imgLarge.html';
                $rootScope.modalStatus = 'modal-show';
                $rootScope.modalTag = 'modal-msg-global';
                $rootScope.mainMsg.url = urls;
                //$rootScope.mainMsg.type = "vipBuyBottom"
            })
        }
       
    }
}]);
